<template>
  <el-card class="security-overview">
    <template #header>
      <div class="card-header">
        <h3>安全概览</h3>
      </div>
    </template>
    
    <div class="security-summary">
      <div class="score-display">
        <div class="score-circle">
          <el-progress 
            type="circle" 
            :percentage="calculateSecurityScore()" 
            :color="getProgressColor()"
            :width="120"
            :stroke-width="8"
            :format="formatScore"
          />
        </div>
        <div class="score-info">
          <h3>安全评分</h3>
          <p>{{ securityScore.securityLevel || '中' }}安全级别</p>
          <div class="score-tips">
            <p v-if="securityScore.suggestions && securityScore.suggestions.length > 0">
              建议：{{ securityScore.suggestions[0] }}
            </p>
          </div>
        </div>
      </div>
      
      <div class="security-items-grid">
        <div 
          v-for="item in securityScore.scoreItems || []" 
          :key="item.name"
          class="security-item-card"
          :class="{ 'completed': item.completed }"
        >
          <div class="item-icon">
            <el-icon :class="item.completed ? 'text-success' : 'text-warning'">
              <Check v-if="item.completed" />
              <Warning v-else />
            </el-icon>
          </div>
          <div class="item-content">
            <h4>{{ item.name }}</h4>
            <p>{{ item.description }}</p>
            <div class="item-score">{{ item.score }}/{{ item.maxScore }}分</div>
          </div>
        </div>
      </div>
    </div>
  </el-card>
</template>

<script setup>
import { Check, Warning } from '@element-plus/icons-vue';

// Props定义
defineProps({
  securityScore: {
    type: Object,
    default: () => ({})
  },
  calculateSecurityScore: {
    type: Function,
    required: true
  },
  getProgressColor: {
    type: Function,
    required: true
  },
  formatScore: {
    type: Function,
    required: true
  }
});
</script>

<style scoped>
.security-overview {
  margin-bottom: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #303133;
}

.security-summary {
  padding: 20px 0;
}

.score-display {
  display: flex;
  align-items: center;
  margin-bottom: 30px;
  gap: 30px;
}

.score-info h3 {
  margin: 0 0 8px 0;
  font-size: 20px;
  color: #303133;
}

.score-info p {
  margin: 0 0 10px 0;
  color: #909399;
  font-size: 14px;
}

.score-tips p {
  color: #E6A23C;
  font-size: 13px;
  margin: 0;
}

.security-items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.security-item-card {
  display: flex;
  align-items: center;
  padding: 16px;
  border: 1px solid #EBEEF5;
  border-radius: 8px;
  transition: all 0.3s;
}

.security-item-card:hover {
  border-color: #409EFF;
  box-shadow: 0 2px 8px rgba(64, 158, 255, 0.1);
}

.security-item-card.completed {
  border-color: #67C23A;
  background-color: #F0F9FF;
}

.item-icon {
  margin-right: 12px;
  font-size: 24px;
}

.text-success {
  color: #67C23A;
}

.text-warning {
  color: #E6A23C;
}

.item-content h4 {
  margin: 0 0 4px 0;
  font-size: 14px;
  font-weight: 600;
  color: #303133;
}

.item-content p {
  margin: 0 0 8px 0;
  font-size: 12px;
  color: #909399;
}

.item-score {
  font-size: 13px;
  font-weight: 600;
  color: #409EFF;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .score-display {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 20px;
  }
  
  .security-items-grid {
    grid-template-columns: 1fr;
  }
}
</style>
